home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8826 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  46 lines

  1. Newsgroups: comp.lang.c++
  2. Path: netcom.com!bnelson
  3. From: bnelson@netcom.com (Bob Nelson)
  4. Subject: Pohl's "C++ for C Programmers"
  5. Message-ID: <bnelsonDnEH5y.Ax0@netcom.com>
  6. Organization: a computer running Linux
  7. X-Newsreader: TIN [version 1.2 PL2]
  8. Date: Mon, 26 Feb 1996 20:34:45 GMT
  9. Sender: bnelson@netcom6.netcom.com
  10.  
  11. As a longtime C programmer now trying to learn C++, I am using Ira
  12. Pohl's "C++ for C Programmers" as my iniitial guide to the language.
  13.  
  14. I am currently stalled because of an issue found in the section
  15. dealing with constructors and destructors, chapter 1.6, (p. 21-22).
  16. NOTE: You'll need to reference that section to follow th rest of this
  17. posting.
  18.  
  19. In particular, Pohl introduces a dynamic storage scheme for the
  20. storage of an array of characters. Prior to this point, the
  21. string's characters were stored in a fixed array.
  22.  
  23. Tied into this is the overloaded '+' operator used to concatenate
  24. two string-type objects. Naturally, it worked as expected when
  25. the class used a fixed array for storage. Once the fixed array
  26. became a dynamic object, the concatentation '+' operator ceased
  27. to work -- which seems only natural since the destructor does
  28. destroy the storage area prior to the assignment of the temporary.
  29. In particular, g++ 2.7.2 (under Linux) returns either an empty
  30. string or a few random trash characten using the concatention operator.
  31.  
  32. I note that Pohl mentions nothing about a possible change that may
  33. need to be made to the the operator routine when the fixed array is
  34. replaced by dynamic storage. (See the class declaration on page 21
  35. and his defintion of the overloaded '+' function on page 18).
  36.  
  37. What changes, if any, do need to be made to permit the concatenation
  38. operator when the fixed array is replaced by dynamic storage?
  39.  
  40. -- 
  41. =============================================================================
  42.           Bob Nelson: Dallas, Texas, U.S.A.  -  bnelson@netcom.com
  43.       Linux for fun, M$ for $$$...and the NFL for what really counts!
  44. =============================================================================
  45.  
  46.